package main

import (
	"flag"
	"fmt"
	"gitee.com/kinwyb/appTools/appTool/code-generate"
	"net/http"
	_ "net/http/pprof"
)

var (
	sourcePath = flag.String("sourcePath", "./", "服务地址")
	outPath    = flag.String("outPath", "./", "输出地址")
	appName    = flag.String("appName", "", "app名称")
	outPkg     = flag.String("outPkg", "", "输出路径的完整包名")
	pprofPort  = flag.Int64("pprof", 0, "pprof端口")
)

func main() {
	flag.Parse()
	if *pprofPort > 0 {
		go func(port int64) {
			err := http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", port), nil)
			if err != nil {
				println("pprof监听异常:" + err.Error())
			}
		}(*pprofPort)
	}
	f := code_generate.NewParseDir(*sourcePath, *outPath, *appName, *outPkg, true)
	err := f.Generate()
	if err != nil {
		println("err : " + err.Error())
	}
	err = f.OutputToFile()
	if err != nil {
		println("err : " + err.Error())
	}
}
